<?php defined('APP_PATH') or exit('Access Denied');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新字段</title>
<link rel="stylesheet" type="text/css" href="vonuo/static/css/vonuo.css">
<script type="text/javascript" src="vonuo/static/js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("input[name='field']").focus();
});
function check_field(){
	var str = $.trim($("input[name='field']").val());
    if(str.match(/^[a-z][a-z0-9]{4,19}$/g) == null){
        $("#need_field").html("<strong style='color:red;'>格式为[5-20]位小写字母和数字组成[必须以字母开头]</strong>");
    }else{
		var value = $("input[name='field']").val();
		var url = "<?php echo spUrl('open','checkfield');?>";
		$.post(url,{field:value,tablename:'<?php echo $tablename;?>'},function(result){
			if(result == 1){
				if(value != '<?php echo $field['field'];?>'){
					$("#need_field").html("<strong style='color:red;'>字段已存在！</strong>");
				}else{
					$("#need_field").html("<strong style='color:red;'>√</strong>");
				}
			}else if(result == 0){
				$("#need_field").html("<strong style='color:red;'>√</strong>");
			}else{
				$("#need_field").html("<strong style='color:red;'>发生未知错误！</strong>");
			}
		});
	}
}
function check(){
	var str = $.trim($("input[name='field']").val());
    if(str.match(/^[a-z][a-z0-9]{4,19}$/g) == null){
		$("#need_field").html("<strong style='color:red;'>格式为[5-20]位小写字母和数字组成[必须以字母开头]</strong>");
		$("input[name='field']").focus();
		return false;
    }
	if($.trim($("input[name='name']").val()) == ''){
		$("#need_name").html("<strong style='color:red;'>请输入名称！</strong>");
		$("input[name='name']").focus();
		return false;
	}else{
		$("#need_name").html("<strong style='color:red;'>√</strong>");
	}
	if($.trim($("select[name='type']").val()) == 'default'){
		$("#need_type").html("<strong style='color:red;'>请选择类型！</strong>");
		$("select[name='type']").focus();
		return false;
	}else if($.trim($("select[name='type']").val()) == '5' || $.trim($("select[name='type']").val()) == '6'){
		if($.trim($("textarea[name='value']").val()) == ''){
			$("#need_value").html("<strong style='color:red;'>请填写选项默认值！格式：选项值1|选项值2</strong>");
			$("#need_value_tr").show();
			$("textarea[name='value']").focus();
			return false;
		}else{
			$("#need_value_tr").hide();
		}
	}else{
		$("#need_type").html("<strong style='color:red;'>√</strong>");
	}
	return true;
}
</script>
</head>

<body>
<div class="gs_wraper gs_p_l0">
	<div class="title">
		<a href="<?php echo spUrl('field','lis',array('modelid'=>$field['modelid']));?>">字段列表</a>
		<a href="javascript:;" class="hover">更新字段</a>
		<a href="javascript:;">预览模型</a>
	</div>
	<form action="<?php echo spUrl('field','doupd',array('fieldid'=>$field['fieldid']));?>" method="post">
	<div class="tab_box" id="con_one_1">
		<table border="0" cellspacing="0" cellpadding="0" class="table_btm">
			<tr>
				<td class="txt_right txt_s_blue">字段：</td>
				<td>
					<input name="field" type="text" value="<?php echo $field['field'];?>" onblur="check_field();" class="blue_input input_w_175" />
					<span id="need_field"></span>
				</td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue">名称：</td>
				<td>
					<input name="name" type="text" value="<?php echo $field['name'];?>" class="blue_input input_w_175" />
					<span id="need_name"></span>
				</td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue">所属模块：</td>
				<td>
					<select name="modelid" class="blue_input input_w_175 f_left" disabled>
					<?php foreach($table as $row){?><option value="<?php echo $row['modelid'];?>" <?php if($row['modelid'] == $field['modelid']){?>selected<?php }?>><?php echo $row['modelname'];?></option><?php }?>
					</select><input name="tablename" value="<?php echo $tablename;?>" type="hidden" />
					<span id="need_modelid" style="margin-left:8px;"></span>
				</td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue">类型：</td>
				<td>
					<select name="typeid" class="blue_input input_w_175 f_left" disabled>
					<?php foreach($type as $row){?>
						<option value="<?php echo $row['typeid'];?>" <?php if($row['typeid'] == $field['typeid']){?>selected<?php }?>><?php echo $row['name'];?></option>
					<?php }?></select>
					<span id="need_type" style="margin-left:8px;"></span>
				</td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue">排序：</td>
				<td><input name="odnum" value="<?php echo $field['odnum'];?>" type="text" class="blue_input input_w_175" /></td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue" valign="top">默认值：</td>
				<td><textarea name="value" cols="40" rows="4" class="blue_textarea"><?php echo $field['value'];?></textarea></td>
			</tr>
			<tr id="need_value_tr" style="display:none;">
				<td class="txt_right txt_s_blue">&nbsp;</td>
				<td><span id="need_value" style="margin-left:8px;"></span></td>
			</tr>
			<tr>
				<td class="txt_right txt_s_blue" valign="top">备注：</td>
				<td><textarea name="tips" cols="40" rows="4" class="blue_textarea"><?php echo $field['tips'];?></textarea></td>
			</tr>
			<tr>
				<td></td>
				<td><a href="javascript:;" onclick="if(check()){$('form').submit();}" class="sure_submit f_left time">确 定</a><a href="<?php echo spUrl('table','lis');?>" class="return_btn f_left">返 回</a></td>
			</tr>
		</table>
	</div>
	</form>
</div>
</body>
</html>